import { useRequest } from 'ahooks'
import { useEffect } from 'react'
import { Http } from '../../../Api'
import Loading from '../../../Currency/Loading'
import { project } from '../../../Data'
import qs from 'qs'

import { LoginSignUpGetUserInfo } from '../../../Login/LoginFunc'

const { hostname } = window.location

const HttpList = {
    'jtgj.ljkjkf.com': {
        username: 'jiaotouchakan',
        password: 'a123456',
        background: 'linear-gradient(0deg, rgba(9, 45, 63, 1),rgba(11, 49, 65, 1))',
    },
}

export const Single = () => {
    const { runAsync: posToken } = useRequest(Http, { manual: true })
    useEffect(() => {
        if (HttpList[hostname]) {
            const { username, password } = HttpList[hostname]
            const { client_id } = project[hostname]
            const data = { client_id, client_secret: 'etime87857872', grant_type: 'password', username, password }
            posToken({ url: 'posToken', data: qs.stringify(data) }).then(res =>
                LoginSignUpGetUserInfo({ ...res, login_type: '0' }),
            )
        }
    }, [posToken])

    return <Loading color={{ background: HttpList[hostname]?.background }} />
}
